<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar bg-white shadow">
        <div class="btn-group tool-button mt5">
            <span>微信公众号：</span>
            <el-select size="medium" v-model="pageForm.wxid" placeholder="请选择" @change="change">
                <el-option
                        v-for="item in wxConfigs"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                </el-option>
            </el-select>
        </div>
        <div class="btn-group tool-button mt5">
            <el-button size="medium" @click="openAdd">
                <i class="ti-plus"></i>
                新建菜单
            </el-button>
        </div>
        <div class="pull-right offscreen-right mt5">
            <el-button size="medium" @click="pushMenu">
                <i class="el-icon-upload"></i>
                推送菜单
            </el-button>
            <el-button size="medium" @click="openSort">
                排序
            </el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table :key="tableKey" :data="tableData" style="width: 100%"  size="small"
                  :highlight-current-row="true" row-key="id" lazy
                  :load="loadChild">
            <el-table-column label="菜单名称" header-align="center" prop="menuName"
                             width="200" :show-overflow-tooltip="true" align="left">

            </el-table-column>

            <el-table-column label="菜单类型" header-align="center" align="center" prop="menuType"
                             :show-overflow-tooltip="true" width="120">
                <template slot-scope="scope">
                    <span v-if="scope.row.menuType==''">菜单</span>
                    <span v-if="scope.row.menuType=='view'">链接</span>
                    <span v-if="scope.row.menuType=='click'">点击事件</span>
                    <span v-if="scope.row.menuType=='miniprogram'">小程序</span>
                </template>
            </el-table-column>

            <el-table-column label="配置内容" header-align="left"
                             :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <span v-if="scope.row.menuType==''">-</span>
                    <span v-if="scope.row.menuType=='view'">{{scope.row.url}}</span>
                    <span v-if="scope.row.menuType=='click'">绑定关键词: {{scope.row.menuKey}}</span>
                    <span v-if="scope.row.menuType=='miniprogram'">小程序appid: {{scope.row.appid}}</span>
                </template>
            </el-table-column>


            <el-table-column label="操作" header-align="center"
                             :show-overflow-tooltip="true" align="center" width="120">
                <template slot-scope="scope">
                    <el-dropdown @command="dropdownCommand">
                        <el-button size="mini">
                            <i class="ti-settings"></i>
                            <span class="ti-angle-down"></span>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item
                                    :command="{type:'add',id:scope.row.id,name:scope.row.menuName}">
                                添加子菜单
                            </el-dropdown-item>
                            <el-dropdown-item divided
                                              :command="{type:'edit',id:scope.row.id,name:scope.row.menuName}">
                                修改
                            </el-dropdown-item>
                            <el-dropdown-item :command="{type:'delete',id:scope.row.id,name:scope.row.menuName}">
                                删除
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>

    </el-row>

    <el-dialog
            title="新建菜单"
            :visible.sync="addDialogVisible"
            :close-on-click-modal="false"
            width="50%">
        <el-form :model="formData" ref="addForm" :rules="formRules" size="small" label-width="80px">
            <el-form-item prop="parentId" label="上级菜单" label-width="80px">
                <el-cascader v-if="!isAddFromSub"
                             style="width: 100%"
                             tabindex="1"
                             :options="menuOptions"
                             :props="props"
                             v-model="parentMenu"
                             placeholder="不选择则为顶级"
                ></el-cascader>
                <el-input v-if="isAddFromSub" type="text" v-model="formData.parentName" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item prop="menuName" label="菜单名称">
                <el-input maxlength="100" placeholder="菜单名称"
                          v-model="formData.menuName"
                          auto-complete="off" tabindex="1" type="text"></el-input>
                <el-alert style="height: 30px;margin-top: 3px;"
                          title="一级菜单最多4个汉字，二级菜单最多7个汉字，多出来的部分将会以“...”代替"
                          type="warning">
                </el-alert>
                <el-alert style="height: 30px;margin-top: 3px;"
                          title="只可设置3个一级菜单，只可设置5个二级菜单"
                          type="warning">
                </el-alert>
            </el-form-item>
            <el-form-item class="is-required" prop="menuType" label="菜单类型">
                <el-radio-group v-model="formData.menuType" size="medium">
                    <el-radio label="">菜单</el-radio>
                    <el-radio label="view">链接</el-radio>
                    <el-radio label="click">点击事件</el-radio>
                    <el-radio label="miniprogram">小程序</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item v-if="formData.menuType=='view'">

                <el-autocomplete
                        style="width: 250px;"
                        :fetch-suggestions="queryChannel"
                        placeholder="请输入标题"
                        @select="handleChannelSelect"
                >
                    <span slot="prepend">搜索栏目</span>
                </el-autocomplete>
                <el-autocomplete
                        style="width: 250px;"
                        :fetch-suggestions="queryArticle"
                        placeholder="请输入标题"
                        @select="handleArticleSelect"
                >
                    <span slot="prepend">搜索文章</span>
                </el-autocomplete>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='view'" prop="url" label="跳转链接">
                <el-input placeholder="网址"
                          v-model="formData.url"
                          auto-complete="off" tabindex="3" type="text"></el-input>
                <el-checkbox v-model="checked1" @change="checkedChange1">网页oauth2.0</el-checkbox>
                <el-checkbox v-model="checked2" @change="checkedChange2">应用oauth2.0</el-checkbox>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='miniprogram'" prop="url" label="url">
                <el-input placeholder="小程序URL"
                          v-model="formData.url"
                          auto-complete="off" tabindex="3" type="text"></el-input>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='miniprogram'" prop="appid" label="appid">
                <el-input placeholder="小程序appid"
                          v-model="formData.appid"
                          auto-complete="off" tabindex="4" type="text"></el-input>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='miniprogram'" prop="pagepath" label="pagepath">
                <el-input placeholder="小程序的页面路径"
                          v-model="formData.pagepath"
                          auto-complete="off" tabindex="5" type="text"></el-input>
            </el-form-item>
            <el-form-item v-if="formData.menuType=='click'" class="is-required" label="绑定事件" prop="menuKey">
                <el-select v-model="formData.menuKey" placeholder="请选择关键词回复">
                    <el-option
                            v-for="item in keyList"
                            :key="item.id"
                            :label="item.value"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="addDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="doAdd">确 定</el-button>
        </span>
    </el-dialog>

    <el-dialog
            title="修改菜单"
            :visible.sync="editDialogVisible"
            :close-on-click-modal="false"
            width="50%">
        <el-form :model="formData" ref="editForm" :rules="formRules" size="small" label-width="80px">
            <el-form-item prop="parentId" label="上级菜单" label-width="80px">
                <el-cascader v-if="!isAddFromSub"
                             style="width: 100%"
                             tabindex="1"
                             :options="menuOptions"
                             :props="props"
                             v-model="parentMenu"
                             placeholder="不选择则为顶级"
                ></el-cascader>
                <el-input v-if="isAddFromSub" type="text" v-model="formData.parentName" :disabled="true"></el-input>
            </el-form-item>
            <el-form-item prop="menuName" label="菜单名称">
                <el-input maxlength="100" placeholder="菜单名称"
                          v-model="formData.menuName"
                          auto-complete="off" tabindex="1" type="text"></el-input>
                <el-alert style="height: 30px;margin-top: 3px;"
                          title="一级菜单最多4个汉字，二级菜单最多7个汉字，多出来的部分将会以“...”代替"
                          type="warning">
                </el-alert>
                <el-alert style="height: 30px;margin-top: 3px;"
                          title="只可设置3个一级菜单，只可设置5个二级菜单"
                          type="warning">
                </el-alert>
            </el-form-item>
            <el-form-item class="is-required" prop="menuType" label="菜单类型">
                <el-radio-group v-model="formData.menuType" size="medium">
                    <el-radio label="">菜单</el-radio>
                    <el-radio label="view">链接</el-radio>
                    <el-radio label="click">点击事件</el-radio>
                    <el-radio label="miniprogram">小程序</el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item v-if="formData.menuType=='view'">

                <el-autocomplete
                        style="width: 250px;"
                        :fetch-suggestions="queryChannel"
                        placeholder="请输入标题"
                        @select="handleChannelSelect"
                >
                    <span slot="prepend">搜索栏目</span>
                </el-autocomplete>
                <el-autocomplete
                        style="width: 250px;"
                        :fetch-suggestions="queryArticle"
                        placeholder="请输入标题"
                        @select="handleArticleSelect"
                >
                    <span slot="prepend">搜索文章</span>
                </el-autocomplete>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='view'" prop="url" label="跳转链接">
                <el-input placeholder="网址"
                          v-model="formData.url"
                          auto-complete="off" tabindex="3" type="text"></el-input>
                <el-checkbox v-model="checked1" @change="checkedChange1">网页oauth2.0</el-checkbox>
                <el-checkbox v-model="checked2" @change="checkedChange2">应用oauth2.0</el-checkbox>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='miniprogram'" prop="url" label="url">
                <el-input placeholder="小程序URL"
                          v-model="formData.url"
                          auto-complete="off" tabindex="3" type="text"></el-input>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='miniprogram'" prop="appid" label="appid">
                <el-input placeholder="小程序appid"
                          v-model="formData.appid"
                          auto-complete="off" tabindex="4" type="text"></el-input>
            </el-form-item>
            <el-form-item class="is-required" v-if="formData.menuType=='miniprogram'" prop="pagepath" label="pagepath">
                <el-input placeholder="小程序的页面路径"
                          v-model="formData.pagepath"
                          auto-complete="off" tabindex="5" type="text"></el-input>
            </el-form-item>
            <el-form-item v-if="formData.menuType=='click'" class="is-required" label="绑定事件" prop="menuKey">
                <el-select v-model="formData.menuKey" placeholder="请选择关键词回复">
                    <el-option
                            v-for="item in keyList"
                            :key="item.id"
                            :label="item.value"
                            :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="editDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="doEdit">确 定</el-button>
        </span>
    </el-dialog>

    <el-dialog
            title="菜单排序"
            :visible.sync="sortDialogVisible"
            width="50%">
        <el-tree
                ref="sortMenuTree"
                :data="sortMenuData"
                draggable
                :allow-drop="sortAllowDrop"
                node-key="id"
                :props="defaultProps"
        >
            <span class="custom-tree-node" slot-scope="scope">
                <span>{{ scope.node.label }}</span>
            </span>
        </el-tree>
        <span slot="footer" class="dialog-footer">
            <el-button @click="sortDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="doSort">确 定</el-button>
        </span>
    </el-dialog>
</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            var wxConfigs = [];
            <!--#for(o in wxList){#-->
            wxConfigs.push({value: "${o.id!}", label: "${o.appname!}"});
            <!--#}#-->
            var self = this;
            var validateUrl = function (rule, value, callback) {
                if ((self.formData.menuType == 'view' || self.formData.menuType == 'miniprogram') && self.formData.url == "") {
                    callback(new Error('请输入正确的URL路径'));
                } else {
                    callback();
                }
            };
            var validateK = function (rule, value, callback) {
                if (self.formData.menuType == 'click' && (typeof(self.formData.menuKey) == "undefined" || self.formData.menuKey == "")) {
                    callback(new Error('请选择关键词'));
                } else {
                    callback();
                }
            };
            var validateA = function (rule, value, callback) {
                if (self.formData.menuType == 'miniprogram' && (typeof(self.formData.appid) == "undefined" || self.formData.appid == "")) {
                    callback(new Error('请输入正确的 appid'));
                } else {
                    callback();
                }
            };
            var validateP = function (rule, value, callback) {
                if (self.formData.menuType == 'miniprogram' && (typeof(self.formData.pagepath) == "undefined" || self.formData.pagepath == "")) {
                    callback(new Error('请输入正确的 pagepath'));
                } else {
                    callback();
                }
            };
            return {
                wxConfigs: wxConfigs,
                addDialogVisible: false,
                editDialogVisible: false,
                sortDialogVisible:false,
                isAddFromSub: false,
                checked1: false,
                checked2: false,
                selectData: [],
                pageForm: {
                    wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->",
                    searchName: "",
                    searchKeyword: "",
                    pageNumber: 1,
                    pageSize: 10,
                    totalCount: 0,
                    pageOrderName: "createdAt",
                    pageOrderBy: "descending"
                },
                tableData: [],//后台取出的数据
                tableKey:"",
                formData: {},
                formRules: {
                    menuName: [
                        {required: true, message: '菜单名称', trigger: 'blur'}
                    ],
                    url: [
                        {required: false, message: '链接', trigger: 'blur'},
                        {validator: validateUrl, trigger: ['blur', 'change']}
                    ],
                    menuKey: [
                        {required: false, message: '绑定关键词', trigger: 'blur'},
                        {validator: validateK, trigger: ['blur', 'change']}
                    ],
                    appid: [
                        {required: false, message: '小程序的appid', trigger: 'blur'},
                        {validator: validateA, trigger: ['blur', 'change']}
                    ],
                    pagepath: [
                        {required: false, message: '小程序的pagepath', trigger: 'blur'},
                        {validator: validateP, trigger: ['blur', 'change']}
                    ]
                },
                menuOptions: [],
                parentMenu: [],
                keyList: [],
                sortMenuData: [],
                defaultProps: {
                    children: 'children',
                    label: 'label'
                },
                props: {
                    lazy: true,
                    checkStrictly:true,
                    multiple:false,
                    lazyLoad: function (node, resolve) {
                        var url = base + "/platform/wx/conf/menu/tree";
                        $.post(url, {pid: node.value,wxid:"<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->"}, function (data) {
                            if (data.code == 0) {
                                resolve(data.data);
                            }
                        }, "json");
                    }
                }
            }
        },
        methods: {
            initTreeTable: function () {
                var self = this;
                var url = base + "/platform/wx/conf/menu/child";
                $.post(url, {pid: "",wxid:"<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->"}, function (data) {
                    if (data.code == 0) {
                        self.tableData = data.data;
                        self.tableKey=+new Date();
                    }
                }, "json");

            },
            loadChild: function (tree, treeNode, resolve) {
                var url = base + "/platform/wx/conf/menu/child";
                $.post(url, {pid: tree.id,wxid:"<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->"}, function (data) {
                    if (data.code == 0) {
                        resolve(data.data);
                    }
                }, "json");
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val).format("YYYY-MM-DD HH:mm");
                return "";
            },
            handleSelectionChange: function (val) {
                this.selectData = val;
            },
            openAdd: function () {
                var self = this;
                self.addDialogVisible = true;
                self.isAddFromSub = false;
                self.formData = {
                    id: "",
                    parentId: "",
                    parentName: "",
                    wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->",
                    menuType: "",
                    url: ""
                };//打开新增窗口,表单先清空
                if (self.$refs["addForm"])
                    self.$refs["addForm"].resetFields();
                self.menuOptions=[];
                self.parentMenu=[];
                self.queryKeyword();
            },
            doAdd: function () {
                var self = this;
                var url = base + "/platform/wx/conf/menu/addDo";
                self.$refs["addForm"].validate(function (valid) {
                    if (valid) {//表单验证通过
                        if (!self.isAddFromSub) {//如果不是添加子菜单，则从级联选择框取父节点ID
                            self.formData.parentId = self.parentMenu[self.parentMenu.length - 1] || "";
                        }
                        $.post(url, self.formData, function (data) {
                            if (data.code == 0) {
                                self.$message({
                                    message: data.msg,
                                    type: 'success'
                                });
                                self.addDialogVisible = false;
                                self.initTreeTable();
                            } else {
                                self.$message({
                                    message: data.msg,
                                    type: 'error'
                                });
                            }
                        }, "json");
                    }
                });
            },
            doEdit: function () {
                var self = this;
                var url = base + "/platform/wx/conf/menu/editDo";
                self.$refs["editForm"].validate(function (valid) {
                    if (valid) {//表单验证通过
                        $.post(url, self.formData, function (data) {
                            if (data.code == 0) {
                                self.$message({
                                    message: data.msg,
                                    type: 'success'
                                });
                                self.editDialogVisible = false;
                                self.initTreeTable();
                            } else {
                                self.$message({
                                    message: data.msg,
                                    type: 'error'
                                });
                            }
                        }, "json");
                    }
                });
            },
            delMore: function () {
                var self = this;
                if (self.selectData.length == 0) {
                    self.$message({
                        message: "请选择消息",
                        type: 'warning'
                    });
                    return false;
                }
                var ids = [];
                self.selectData.forEach(function (val) {
                    ids.push(val.id);
                });
                self.$confirm('您确定要删除选中的 ' + ids.length + ' 条数据？ ', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    callback: function (a, b) {
                        if ("confirm" == a) {//确认后再执行
                            $.post(base + "/platform/wx/conf/menu/delete", {ids: ids.toString()}, function (data) {
                                if (data.code == 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.initTreeTable();
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        }
                    }
                });
            },
            dropdownCommand: function (command) {//监听下拉框事件
                var self = this;
                if ("add" == command.type) {
                    self.openAdd();
                    self.formData.parentId = command.id;
                    self.formData.parentName = command.name;
                    self.isAddFromSub = true;
                }
                if ("edit" == command.type) {
                    $.post(base + "/platform/wx/conf/menu/edit/" + command.id, {}, function (data) {
                        if (data.code == 0) {
                            self.formData = data.data;//加载后台表单数据
                            self.editDialogVisible = true;//打开编辑窗口
                            self.queryKeyword();
                        } else {
                            self.$message({
                                message: data.msg,
                                type: 'error'
                            });
                        }
                    }, "json");
                }
                if ("delete" == command.type) {
                    self.$confirm('此操作将删除： ' + command.name, '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning',
                        callback: function (a, b) {
                            if ("confirm" == a) {//确认后再执行
                                $.post(base + "/platform/wx/conf/menu/delete/" + command.id, {}, function (data) {
                                    if (data.code == 0) {
                                        self.$message({
                                            message: data.msg,
                                            type: 'success'
                                        });
                                        self.initTreeTable();
                                    } else {
                                        self.$message({
                                            message: data.msg,
                                            type: 'error'
                                        });
                                    }
                                }, "json");
                            }
                        }
                    });
                }
            },
            queryChannel: function (queryString, cb) {
                $.post(base + "/platform/wx/reply/news/channel_data", {
                    searchName: "name",
                    searchKeyword: queryString,
                    pageNumber: 1,
                    pageSize: 10,
                    pageOrderName: "createdAt",
                    pageOrderBy: "descending"
                }, function (data) {
                    if (data.code == 0) {
                        var res = [];
                        data.data.list.forEach(function (o) {
                            res.push({value: o.name, id: o.id})
                        });
                        cb(res);
                    }
                }, "json");
            },
            handleChannelSelect: function (val) {
                var domain = "${AppDomain!}";
                this.formData.url = domain + base + "/public/wx/cms/channel/" + val.id;
            },
            queryArticle: function (queryString, cb) {
                $.post(base + "/platform/wx/reply/news/article_data", {
                    searchName: "title",
                    searchKeyword: queryString,
                    pageNumber: 1,
                    pageSize: 10,
                    pageOrderName: "createdAt",
                    pageOrderBy: "descending"
                }, function (data) {
                    if (data.code == 0) {
                        var res = [];
                        data.data.list.forEach(function (o) {
                            res.push({value: o.title, id: o.id})
                        });
                        cb(res);
                    }
                }, "json");
            },
            handleArticleSelect: function (val) {
                var domain = "${AppDomain!}";
                this.formData.url = domain + base + "/public/wx/cms/article/" + val.id;
            },
            checkedChange1: function (val) {
                if (this.checked1) {
                    var str = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.appid!}<!--#}#-->&redirect_uri=$s&response_type=code&scope=snsapi_base&state=11624317#wechat_redirect";
                    this.formData.url = str.replace("$s", encodeURIComponent(this.formData.url));
                } else {
                    var url = this.formData.url;
                    var str = url.substring(url.indexOf("redirect_uri=") + 13, url.indexOf("&response_type="));
                    this.formData.url = decodeURIComponent(str);
                }
            },
            checkedChange2: function (val) {
                if (this.checked2) {
                    var str = "${AppDomain!}${base!}/public/wechat/<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->/oauth?goto_url=$s";
                    this.formData.url = str.replace("$s", this.formData.url);
                } else {
                    var url = this.formData.url;
                    this.formData.url = url.substring(url.indexOf("goto_url=") + 9);
                }
            },
            queryKeyword: function () {
                var self = this;
                $.post(base + "/platform/wx/conf/menu/keywordData", {wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->"}, function (data) {
                    if (data.code == 0) {
                        var res = [];
                        data.data.forEach(function (o) {
                            res.push({value: o.keyword, id: o.keyword})
                        });
                        self.keyList = res;
                    }
                }, "json");
            },
            pushMenu: function () {
                var self=this;
                self.$confirm('确定要将菜单推送到微信平台？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    callback: function (a, b) {
                        if ("confirm" == a) {//确认后再执行
                            $.post(base + "/platform/wx/conf/menu/pushMenu", { wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->"}, function (data) {
                                if (data.code == 0) {
                                    self.$message({
                                        message: data.msg,
                                        type: 'success'
                                    });
                                    self.initTreeTable();
                                } else {
                                    self.$message({
                                        message: data.msg,
                                        type: 'error'
                                    });
                                }
                            }, "json");
                        }
                    }
                });
            },
            //排序树加载
            sortMenuLoad: function () {
                var self = this;
                $.post(base + "/platform/wx/conf/menu/sort", {wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->"}, function (data) {
                    if (data.code == 0) {
                        self.sortMenuData = data.data;
                    }
                }, "json");
            },
            //排序树控制不可跨级拖拽
            sortAllowDrop: function (moveNode, inNode, type) {
                if (moveNode.data.parentId == inNode.data.parentId) {
                    return type == 'prev';
                }
            },
            //打开排序功能
            openSort: function () {
                this.sortDialogVisible = true;
                this.sortMenuLoad();
            },
            //递归获取所有的ID值
            getTreeIds: function (ids, data) {
                var self = this;
                data.forEach(function (obj) {
                    ids.push(obj.id);
                    if (obj.children && obj.children.length > 0) {
                        self.getTreeIds(ids, obj.children);
                    }
                });
            },
            //提交排序后的数据
            doSort: function () {
                var self = this;
                var ids = [];
                self.getTreeIds(ids, self.sortMenuData);
                $.post(base + "/platform/wx/conf/menu/sortDo", {wxid: "<!--#if(!isEmpty(wxConfig)){#-->${wxConfig.id!}<!--#}#-->",ids: ids.toString()}, function (data) {
                    if (data.code == 0) {
                        self.$message({
                            message: data.msg,
                            type: 'success'
                        });
                        self.sortDialogVisible = false;
                        self.initTreeTable();
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            change: function (val) {
                window.location.href = "${base}/platform/wx/conf/menu/index/" + val;
            }
        },
        created: function () {
            this.initTreeTable();
        }
    });
</script>
<!--#
}
#-->